package com.gj.xxl.job.admin.core.route;

import com.gj.xxl.job.admin.core.route.strategy.*;

public enum RouteStrategyEnum {
    FIRST("FIRST", new FirstRouteStrategy()),
    LAST("LAST", new LastRouteStrategy()),
    ROUND("ROUND", new RoundRouteStrategy()),
    RANDOM("RANDOM", new RandomRouteStrategy()),
    FAILOVER("FAILOVER", new FailOverRouteStrategy());


    private String routeName;

    private RouteStrategy routeStrategy;

    RouteStrategyEnum(String routeName, RouteStrategy routeStrategy) {
        this.routeName = routeName;
        this.routeStrategy = routeStrategy;
    }


    public String getRouteName() {
        return routeName;
    }

    public RouteStrategy getRouteStrategy() {
        return routeStrategy;
    }

    public static RouteStrategyEnum match(String routeName, RouteStrategyEnum defaultItem) {
        if (routeName != null) {
            for (RouteStrategyEnum item : RouteStrategyEnum.values()) {
                if (routeName.equals(item.getRouteName())) {
                    return item;
                }
            }
        }
        return defaultItem;
    }
}
